﻿//GB/Z 29014.3 ISYC 307-01-柄连接可转位刀片非中心切削单排立铣刀

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;

namespace TestDxfDocument
{
    class ISYC_307_01_F69
    {
        public static void ISYC_307_F69_H(Dictionary<string, Object> data) //柄连接可转位刀片非中心切削单排立铣刀
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //基本参数-------------------------------------------------------------------------------------------------
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            //赋值参数--------------------------------------------------------------------------------------------------
            double scale = 1;
            double OAL = 51.79 * scale;
            double LPR = 33.35 * scale;
            double APMX = 3.34 * scale;
            double DC = 4.37 * scale;
            double LF = 40.86 * scale;
            double LU = 17.48 * scale;
            double BD = 9.87 * scale;
            double DCX = 13.05 * scale;
            double DCONMS = 11.13 * scale;
            double LS = 24.07 * scale;
            double KAPR = 38;

            //点---------------------------------------------------------------------------------------------
            //第一部分
            //轮廓
            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(v1.X + OAL, v1.Y);
            Vector2 v4 = new Vector2(v1.X + (0.57 / 24.07) * LS, v1.Y + DCONMS / 2.0);
            Vector2 v3 = fun.Inters(v1, fun.Polar(v1, 90 * pi / 180, DCONMS), v4, fun.Polar(v4, -135 * pi / 180, OAL));
            Vector2 v5 = new Vector2(v3.X + LS, v4.Y);
            Vector2 v6 = new Vector2(v5.X + (0.57 / 24.07) * LS, v5.Y - (0.57 / 24.07) * LS);
            Vector2 v7 = new Vector2(v1.X + OAL, v1.Y + DC / 2.0);
            Vector2 v8 = new Vector2(v2.X - APMX, v2.Y + DCX / 2.0);
            Vector2 v9 = fun.Inters(v8, fun.Polar(v8, -(150 - KAPR) * pi / 180, OAL), v7, fun.Polar(v7, -(210 - KAPR) * pi / 180, OAL));
            Vector2 v10 = fun.Inters(v6, fun.Polar(v6, 0 * pi / 180, OAL), v8, v9);
            Vector2 v13 = new Vector2(v2.X - (1.28 / 3.34) * APMX, v2.Y);
            Vector2 v11 = fun.Inters(v13, fun.Polar(v13, 90 * pi / 180, OAL), v7, v9);
            Vector2 v12 = fun.Inters(v8, fun.Polar(v9, fun.CalAngle(v9, v7), fun.CalDistance(v9, v7) / 2.0), v7, fun.Polar(v9, fun.CalAngle(v9, v8), fun.CalDistance(v9, v7) / 2.0));
            Vector2 v14 = new Vector2(v11.X, -v11.Y);
            Vector2 v15 = new Vector2(v7.X, -v7.Y);
            Vector2 v16 = new Vector2(v8.X, -v8.Y);
            Vector2 v17 = new Vector2(v10.X, -v10.Y);
            Vector2 v19 = new Vector2(v2.X - APMX, v2.Y);
            Vector2 v18 = fun.Inters(v17, fun.Polar(v17, 0 * pi / 180, OAL), v19, fun.Polar(v19, -90 * pi / 180, OAL));
            Vector2 v20 = new Vector2(v6.X, -v6.Y);
            Vector2 v21 = new Vector2(v5.X, -v5.Y);
            Vector2 v22 = new Vector2(v4.X, -v4.Y);
            Vector2 v23 = new Vector2(v3.X, -v3.Y);
            Vector2 v28 = new Vector2(v2.X - LF, v2.Y);
            Vector2 v24 = new Vector2(v28.X - (3.92 / 24.07) * LS, v2.Y + (3.5 / 11.13) * DCONMS);
            Vector2 v25 = new Vector2(v28.X + (v28.X - v24.X), v24.Y);
            Vector2 v26 = new Vector2(v25.X, -v25.Y);
            Vector2 v27 = new Vector2(v24.X, -v24.Y);
            Vector2 v29 = new Vector2(v28.X + (7.51 / 24.07) * LS, v28.Y);
            Vector2 v30 = new Vector2(v28.X - (1.4 / 24.07) * LS, v28.Y + (12.05 / 13.05) * DCX);
            Vector2 v31 = new Vector2(v30.X + (6.25 / 24.07) * LS, v30.Y);
            Vector2 v32 = fun.Inters(v31, fun.Polar(v31, -21 * pi / 180, OAL), v29, fun.Polar(v29, 90 * pi / 180, OAL));
            Vector2 v33 = new Vector2(v32.X, -v32.Y);
            Vector2 v34 = new Vector2(v31.X, -v31.Y);
            Vector2 v35 = new Vector2(v30.X, -v30.Y);
            Vector2 v36 = new Vector2(v22.X - (4 / 24.07) * LS, v22.Y - (4.67 / 11.13) * DCONMS);
            Vector2 v37 = new Vector2(v6.X + (6.98 / 17.48) * LU, v6.Y);
            Vector2 v38 = new Vector2(v8.X + (14.17 / 51.79) * OAL, v8.Y + (18.83 / 13.05) * DCX);
            Vector2 v39 = new Vector2(v2.X + (40 / 51.79) * OAL, v2.Y);
            Vector2 v40 = new Vector2(v39.X + (25 / 51.79) * OAL, v39.Y);
            Vector2 v41 = new Vector2(v40.X + DCONMS * 1.2, v40.Y);
            Vector2 v42 = new Vector2(v40.X + (fun.CalDistance(v40, v41) / 2.0), v40.Y);
            Vector2 v43 = new Vector2(v42.X - DCONMS / 2.0, v42.Y);
            Vector2 v44 = new Vector2(v42.X, v42.Y + DCX / 2.0);
            Vector2 v45 = new Vector2(v42.X + (0.86 / 13.05) * DCX, v44.Y - (0.5 / 13.05) * DCX);
            Vector2 v45_1 = new Vector2(v45.X, v45.Y - (4.36 / 13.05) * DCX);
            Vector2 v44_1 = fun.Inters(v43, fun.Polar(v43, 10 * pi / 180, OAL), v45_1, fun.Polar(v45_1, -153 * pi / 180, OAL));
            Vector2 v46 = fun.Inters(v44, fun.Polar(v44, -90 * pi / 180, OAL), v44_1, v45_1);
            Vector2 v47 = new Vector2(v44.X, v44.Y - (2.54 / 13.05) * DCX);
            Vector2 v48 = new Vector2(v47.X, v47.Y - (1.53 / 13.05) * DCX);
            Vector2 v49 = fun.Inters(v48, fun.Polar(v48, 21 * pi / 180, OAL), v45, fun.Polar(v45, -90 * pi / 180, OAL));
            Vector2 v50 = new Vector2(v44.X, -v44.Y);
            Vector2 v51 = fun.rotatePoint_Changed(v42, v45, 180);
            Vector2 v52 = fun.rotatePoint_Changed(v42, v45_1, 180);
            Vector2 v53 = fun.rotatePoint_Changed(v42, v44_1, 180);
            Vector2 v54 = fun.rotatePoint_Changed(v42, v43, 180);
            Vector2 v55 = fun.rotatePoint_Changed(v42, v47, 180);
            Vector2 v56 = fun.rotatePoint_Changed(v42, v49, 180);
            Vector2 v57 = fun.rotatePoint_Changed(v42, v48, 180);
            Vector2 v58 = fun.getPointForArcandLine(v52, v51, v42, new Arc(v42, DCONMS / 2.0, 0, 360));
            Vector2 v59 = new Vector2(v50.X, v42.Y - DCONMS / 2.0);
            Vector2 v60 = fun.rotatePoint_Changed(v42, v59, 180);
            Vector2 v61 = fun.rotatePoint_Changed(v42, v58, 180);
            Vector2 v46_1 = fun.rotatePoint_Changed(v42, v46, 180);

            //作图部分-----------------------------------------------------------------------
            //中心线
            Line line1 = new Line(v1, v2);
            line1.Layer = centre;
            line1.Linetype = Linetype.Center;
            line1.LinetypeScale = 5;
            dxf.AddEntity(line1);

            Line line2 = new Line(v40, v41);
            line2.Layer = centre;
            line2.Linetype = Linetype.Center;
            line2.LinetypeScale = 5;
            dxf.AddEntity(line2);

            Line line3 = new Line(v44, v50);
            line3.Layer = centre;
            line3.Linetype = Linetype.Center;
            line3.LinetypeScale = 5;
            dxf.AddEntity(line3);

            //第一部分
            //轮廓
            LwPolyline polyline1 = new LwPolyline();
            polyline1.Vertexes.Add(new LwPolylineVertex(v1));
            polyline1.Vertexes.Add(new LwPolylineVertex(v3));
            polyline1.Vertexes.Add(new LwPolylineVertex(v4));
            polyline1.Vertexes.Add(new LwPolylineVertex(v5));
            polyline1.Vertexes.Add(new LwPolylineVertex(v6));
            polyline1.Vertexes.Add(new LwPolylineVertex(v10));
            fun.PolyFill(dxf, polyline1, 0.3, contour);

            LwPolyline polyline2 = new LwPolyline();
            polyline2.Vertexes.Add(new LwPolylineVertex(v7));
            polyline2.Vertexes.Add(new LwPolylineVertex(v8));
            polyline2.Vertexes.Add(new LwPolylineVertex(v9));
            polyline2.Vertexes.Add(new LwPolylineVertex(v7));
            fun.PolyFill(dxf, polyline2, 0.3, contour);

            LwPolyline polyline3 = new LwPolyline();
            polyline3.Vertexes.Add(new LwPolylineVertex(v11));
            polyline3.Vertexes.Add(new LwPolylineVertex(v14));
            polyline3.Vertexes.Add(new LwPolylineVertex(v18));
            polyline3.Vertexes.Add(new LwPolylineVertex(v20));
            polyline3.Vertexes.Add(new LwPolylineVertex(v21));
            polyline3.Vertexes.Add(new LwPolylineVertex(v22));
            polyline3.Vertexes.Add(new LwPolylineVertex(v23));
            polyline3.Vertexes.Add(new LwPolylineVertex(v1));
            fun.PolyFill(dxf, polyline3, 0.3, contour);

            LwPolyline polyline4 = new LwPolyline();
            polyline4.Vertexes.Add(new LwPolylineVertex(v24));
            polyline4.Vertexes.Add(new LwPolylineVertex(v25));
            polyline4.Vertexes.Add(new LwPolylineVertex(v26));
            polyline4.Vertexes.Add(new LwPolylineVertex(v27));
            polyline4.Vertexes.Add(new LwPolylineVertex(v24));
            fun.PolyFill(dxf, polyline4, 0.3, contour);

            LwPolyline polyline5 = new LwPolyline();
            polyline5.Vertexes.Add(new LwPolylineVertex(v24));
            polyline5.Vertexes.Add(new LwPolylineVertex(v27));//0
            polyline5.Vertexes[0].Bulge = Math.Tan(84 * pi / 180 / 4);
            fun.PolyFill(dxf, polyline5, 0.3, contour);

            LwPolyline polyline6 = new LwPolyline();
            polyline6.Vertexes.Add(new LwPolylineVertex(v25));
            polyline6.Vertexes.Add(new LwPolylineVertex(v26));//0
            polyline6.Vertexes[0].Bulge = Math.Tan(-84 * pi / 180 / 4);
            fun.PolyFill(dxf, polyline6, 0.3, contour);

            LwPolyline polyline7 = new LwPolyline();
            polyline7.Vertexes.Add(new LwPolylineVertex(v37));
            polyline7.Vertexes.Add(new LwPolylineVertex(v19));//0
            polyline7.Vertexes.Add(new LwPolylineVertex(v13));
            polyline7.Vertexes[0].Bulge = Math.Tan(37 * pi / 180 / 4);
            fun.PolyFill(dxf, polyline7, 0.3, contour);

            LwPolyline polyline8 = new LwPolyline();
            polyline8.Vertexes.Add(new LwPolylineVertex(v19));
            polyline8.Vertexes.Add(new LwPolylineVertex(v18));
            fun.PolyFill(dxf, polyline8, 0.3, contour);

            LwPolyline polyline9 = new LwPolyline();
            polyline9.Vertexes.Add(new LwPolylineVertex(v14));
            polyline9.Vertexes.Add(new LwPolylineVertex(v15));
            polyline9.Vertexes.Add(new LwPolylineVertex(v16));
            polyline9.Vertexes.Add(new LwPolylineVertex(v17));
            fun.PolyFill(dxf, polyline9, 0.3, contour);

            LwPolyline polyline10 = new LwPolyline();
            polyline10.Vertexes.Add(new LwPolylineVertex(v4));
            polyline10.Vertexes.Add(new LwPolylineVertex(v22));
            fun.PolyFill(dxf, polyline10, 0.3, contour);

            LwPolyline polyline11 = new LwPolyline();
            polyline11.Vertexes.Add(new LwPolylineVertex(v5));
            polyline11.Vertexes.Add(new LwPolylineVertex(v21));
            fun.PolyFill(dxf, polyline11, 0.3, contour);

            LwPolyline polyline12 = new LwPolyline();
            polyline12.Vertexes.Add(new LwPolylineVertex(v6));
            polyline12.Vertexes.Add(new LwPolylineVertex(v20));
            fun.PolyFill(dxf, polyline12, 0.3, contour);

            fun.drawcircle(dxf, v12, (0.7 / 3.34) * APMX, 0.3, contour);

            //虚线
            LwPolyline polyline13 = new LwPolyline();
            polyline13.Vertexes.Add(new LwPolylineVertex(v30));
            polyline13.Vertexes.Add(new LwPolylineVertex(v31));
            polyline13.Vertexes.Add(new LwPolylineVertex(v32));
            polyline13.Vertexes.Add(new LwPolylineVertex(v33));
            polyline13.Vertexes.Add(new LwPolylineVertex(v34));
            polyline13.Vertexes.Add(new LwPolylineVertex(v35));
            polyline13.Linetype = Linetype.Dashed;
            polyline13.LinetypeScale = 5;
            polyline13.Layer = refin;
            dxf.AddEntity(polyline13);

            //第二部分
            //轮廓
            LwPolyline polyline14 = new LwPolyline();
            polyline14.Vertexes.Add(new LwPolylineVertex(v43));
            polyline14.Vertexes.Add(new LwPolylineVertex(v44_1));
            polyline14.Vertexes.Add(new LwPolylineVertex(v45_1));
            polyline14.Vertexes.Add(new LwPolylineVertex(v45));
            polyline14.Vertexes.Add(new LwPolylineVertex(v44));
            polyline14.Vertexes.Add(new LwPolylineVertex(v46));
            fun.PolyFill(dxf, polyline14, 0.3, contour);

            LwPolyline polyline15 = new LwPolyline();
            polyline15.Vertexes.Add(new LwPolylineVertex(v43));
            polyline15.Vertexes.Add(new LwPolylineVertex(v47));//0
            polyline15.Vertexes[0].Bulge = Math.Tan(-88 * pi / 180 / 4);
            fun.PolyFill(dxf, polyline15, 0.3, contour);

            LwPolyline polyline16 = new LwPolyline();
            polyline16.Vertexes.Add(new LwPolylineVertex(v48));
            polyline16.Vertexes.Add(new LwPolylineVertex(v49));
            fun.PolyFill(dxf, polyline16, 0.3, contour);

            LwPolyline polyline17 = new LwPolyline();
            polyline17.Vertexes.Add(new LwPolylineVertex(v54));
            polyline17.Vertexes.Add(new LwPolylineVertex(v53));
            polyline17.Vertexes.Add(new LwPolylineVertex(v52));
            polyline17.Vertexes.Add(new LwPolylineVertex(v51));
            polyline17.Vertexes.Add(new LwPolylineVertex(v50));
            polyline17.Vertexes.Add(new LwPolylineVertex(v46_1));
            fun.PolyFill(dxf, polyline17, 0.3, contour);

            LwPolyline polyline18 = new LwPolyline();
            polyline18.Vertexes.Add(new LwPolylineVertex(v54));
            polyline18.Vertexes.Add(new LwPolylineVertex(v55));
            polyline18.Vertexes[0].Bulge = Math.Tan(-88 * pi / 180 / 4);
            fun.PolyFill(dxf, polyline18, 0.3, contour);

            LwPolyline polyline19 = new LwPolyline();
            polyline19.Vertexes.Add(new LwPolylineVertex(v56));
            polyline19.Vertexes.Add(new LwPolylineVertex(v57));
            fun.PolyFill(dxf, polyline19, 0.3, contour);

            var arc1 = fun.DrawArc3(v60, v43, v58);
            fun.drawBArc(dxf, arc1, 0.3, contour);

            var arc2 = fun.DrawArc3(v59, v54, v61);
            fun.drawBArc(dxf, arc2, 0.3, contour);

            //标注---------------------------------------------------------------------------
            double height = 2 * scale;
            double arrowsize = 1 * scale;
            double exline = 0.5 * scale;

            //坐标系
            fun.Axis(dxf, v28, 180, 270, "", "", "PCS", 0.2 * scale, height * 0.5, 0);
            fun.Axis(dxf, v29, 180, 270, "", "", "MCS", 0.2 * scale, height * 0.5, 0);
            fun.Axis(dxf, v36, 180, 270, "Z", "Y", "X", 0.2 * scale, height * 0.5, 0);

            //DCONMS
            fun.dimrot1(dxf, v4, v22, 90, LS * 0.3, 0.1, height, arrowsize, exline, "DCONMS", "", "");

            //LS
            fun.dimrot1(dxf, v23, v21, 180, DCONMS * 1.1, 0.1, height, arrowsize, exline, "LS", "", "");

            //OAL
            fun.dimrot1(dxf, v3, v7, 0, DCONMS * 3, 0.1, height, arrowsize, exline, "OAL", "", "");

            //LF
            fun.dimrot1(dxf, v28, v7, 0, DCONMS * 2.8, 0.1, height, arrowsize, exline, "LF", "", "");

            //LPR
            fun.dimrot1(dxf, v32, v7, 0, DCONMS * 1.5, 0.1, height, arrowsize, exline, "LPR", "", "");

            //LU
            fun.dimrot1(dxf, new Vector2(v37.X + (2.7 / 17.48) * LU, v37.Y), v7, 0, DCONMS * 1, 0.1, height, arrowsize, exline, "LU", "", "");

            //DCX
            fun.dimrot1(dxf, v8, v16, -90, OAL * 0.6, 0.1, height, arrowsize, exline, "DCX", "", "");

            //BD
            fun.dimrot1(dxf, fun.Polar(v8, -(90 - KAPR) * pi / 180, (1.93 / 5.48) * fun.CalDistance(v7, v8)), fun.Polar(v16, (90 - KAPR) * pi / 180, (1.93 / 5.48) * fun.CalDistance(v7, v8)), -90, OAL * 0.4, 0.1, height, arrowsize, exline, "BD", "", "");

            //DC
            fun.dimrot1(dxf, v7, v15, -90, OAL * 0.2, 0.1, height, arrowsize, exline, "DC", "", "");

            //APMX
            fun.dimrot1(dxf, v16, v15, 180, DCONMS, 0.1, height, arrowsize, exline, "APMX", "", "");

            //角度标注
            //KAPR
            fun.jdbz2(dxf, new Line(v7, fun.Polar(v7, 90 * pi / 180, 0.1)), new Line(v7, fun.Polar(v7, (90 + KAPR) * pi / 180, 0.1)), DCONMS * 0.8, height, arrowsize, exline, "KAPR", "", "");

            //箭头
            //FDP
            fun.jt1(dxf, v38, -90, 5, 1, "FDP", height);

            //CCMS
            fun.jt1(dxf, new Vector2(v4.X + (9.05 / 24.07) * LS, v4.Y), 100, 5, 1, "CCMS", height);

            //A
            fun.jt1(dxf, v39, 0, 5, 1, "A", height);

            //字符
            fun.text(dxf, new Vector2(v44.X - (2.45 / 11.13) * DCONMS, v44.Y + (2.24 / 11.13) * DCONMS), height, "View A");

            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
    }
}
